<?php
class MemberShowAction extends BaseAction {
	public function showMember() {
		//防止页面乱码  
		header ( 'Content-type:text/html;charset=utf-8' );
		$Show = M('Show');
		for($i=0;$i<8;$i++) {
			$j=$i+1;
			if(is_file('Public/Display/index/member/female0'.$j.'.jpg')) {
				$condition['show_type'] = '非缘莫属女';
				$condition['show_seq'] = $j;
				$female = $Show->where($condition)->find();
				$femalelist[$i]['user_id'] = $female['show_url'];
				$femalelist[$i]['photo_id'] = 'female0'.$j;
				$femalelist[$i]['photo_url'] = '__PUBLIC__/Display/index/member/female0'.$j.'.jpg';
			}
			if(is_file('Public/Display/index/member/male0'.$j.'.jpg')) {
				$condition['show_type'] = '非缘莫属男';	
				$condition['show_seq'] = $j;
				$male = $Show->where($condition)->find();
				$malelist[$i]['user_id'] = $male['show_url'];
				$malelist[$i]['photo_id'] = 'male0'.$j;
				$malelist[$i]['photo_url'] = '__PUBLIC__/Display/index/member/male0'.$j.'.jpg';
			}	
		}
		
		$this->assign('femalelist',$femalelist);
		$this->assign('malelist',$malelist);
		$this->assign('navi',"会员展示列表");
		$this->assign('title',"非缘莫属");
		$this->display();
	}
	
public function showVip() {
		//防止页面乱码  
		header ( 'Content-type:text/html;charset=utf-8' );
		$Show = M('Show');
		for($i=0;$i<8;$i++) {
			$j=$i+1;
			if(is_file('Public/Display/index/vip/female0'.$j.'.jpg')) {
				$condition['show_type'] = '绝对精英女';
				$condition['show_seq'] = $j;
				$female = $Show->where($condition)->find();
				$femalelist[$i]['user_id'] = $female['show_url'];
				$femalelist[$i]['photo_id'] = 'female0'.$j;
				$femalelist[$i]['photo_url'] = '__PUBLIC__/Display/index/vip/female0'.$j.'.jpg';
			}
			if(is_file('Public/Display/index/vip/male0'.$j.'.jpg')) {
				$condition['show_type'] = '绝对精英男';	
				$condition['show_seq'] = $j;
				$male = $Show->where($condition)->find();
				$malelist[$i]['user_id'] = $male['show_url'];
				$malelist[$i]['photo_id'] = 'male0'.$j;
				$malelist[$i]['photo_url'] = '__PUBLIC__/Display/index/vip/male0'.$j.'.jpg';
			}	
		}
		
		$this->assign('femalelist',$femalelist);
		$this->assign('malelist',$malelist);
		$this->assign('navi',"会员展示列表");
		$this->assign('title',"绝对精英");
		$this->display();
	}
	
	public function showBanner() {
		//防止页面乱码  
		header ( 'Content-type:text/html;charset=utf-8' );
		$Show = M('Show');
		for($i=0;$i<5;$i++) {
			$j=$i+1;
			if(is_file('Public/Display/index/outing/bt0'.$j.'.jpg')) {
				$labellist[$i]['photo_id'] = 'bt0'.$j;
				$labellist[$i]['photo_url'] = '__PUBLIC__/Display/index/outing/bt0'.$j.'.jpg';
			}
			if(is_file('Public/Display/index/outing/img0'.$j.'.jpg')) {
				$condition['show_type'] = '首页横幅';	
				$condition['show_seq'] = $j;
				$banner = $Show->where($condition)->find();
				$bannerlist[$i]['user_id'] = $banner['show_url'];
				$bannerlist[$i]['photo_id'] = 'img0'.$j;
				$bannerlist[$i]['photo_url'] = '__PUBLIC__/Display/index/outing/img0'.$j.'.jpg';
			}	
		}
		
		$this->assign('bannerlist',$bannerlist);
		$this->assign('labellist',$labellist);
		$this->assign('navi',"首页横幅列表");
		$this->assign('title',"首页横幅");
		$this->display();
	}
	
	public function showArticle() {
		//防止页面乱码  
		header ( 'Content-type:text/html;charset=utf-8' );
		$Page = M('page'); 
		
		$id = $_GET['id'];
		if($id==1) {
			$condition['page_type'] = '品牌合作';
			$navi = "品牌合作";
			$title = "品牌合作内容";
		}
		else if($id==2) {
			$condition['page_type'] = '诚聘贤士';
			$navi = "诚聘贤士";
			$title = "招聘内容";
		}	
		$info = $Page->where($condition)->find();
		$this->assign('navi',$navi);
		$this->assign('title',$title);
		$this->assign('page',$info);
		$this->display();
	}
	
	public function modify() {
		//防止页面乱码  
		header ( 'Content-type:text/html;charset=utf-8' );
		$Page = M('page');
		$condition['page_type'] = $_POST['type'];
		if($_POST['type']=='品牌合作') $jumpurl = '1';
		else if($_POST['type']=='诚聘贤士') $jumpurl = '2';
		$info = $Page->where($condition)->find();
		
		if($info['page_date']!=$_POST['date']) $data['page_date'] = $_POST['date'];
		if($info['title']!=$_POST['title']) $data['title'] = $_POST['title'];
		if($info['content']!=$_POST['content']) $data['content'] = $_POST['content'];
		if($data) {
			$result = $Page->where($condition)->save($data);
			if($result)
				echo "<script language=\"javascript\">alert('更新成功！');window.location.href='showArticle/id/".$jumpurl."';</script>";
			else 
				$this->error ( '数据写入错误！请重试...' );
		}
		else echo "<script language=\"javascript\">alert('资料没有更新！');window.history.back();</script>";
	}
	
	public function setMemberUserId() {
		//防止页面乱码  
		header ( 'Content-type:text/html;charset=utf-8' );
		$Show = M('Show');
		$photo_id = $_GET['photoid'];
		$user_id = $_GET['userid'];
		if(strlen($photo_id)==6) {
			$condition['show_type'] = '非缘莫属男';	
			$condition['show_seq'] = substr($photo_id,5,1);
			$data['show_url'] = $user_id;	
			$Show->where($condition)->save($data);
		} else {
			$condition['show_type'] = '非缘莫属女';
			$condition['show_seq'] = substr($photo_id,7,1);
			$data['show_url'] = $user_id;	
			$Show->where($condition)->save($data);
		}
		$this->redirect('showMember');
	}
	
	public function setVipUserId() {
		//防止页面乱码  
		header ( 'Content-type:text/html;charset=utf-8' );
		$Show = M('Show');
		$photo_id = $_GET['photoid'];
		$user_id = $_GET['userid'];
		if(strlen($photo_id)==6) {
			$condition['show_type'] = '绝对精英男';	
			$condition['show_seq'] = substr($photo_id,5,1);
			$data['show_url'] = $user_id;	
			$Show->where($condition)->save($data);
		} else {
			$condition['show_type'] = '绝对精英女';
			$condition['show_seq'] = substr($photo_id,7,1);
			$data['show_url'] = $user_id;	
			$Show->where($condition)->save($data);
		}
		$this->redirect('showVip');
	}
	
	public function setUrl() {
		//防止页面乱码  
		header ( 'Content-type:text/html;charset=utf-8' );
		$Show = M('Show');
		$photo_id = $_GET['photoid'];
		$url = $_GET['url'];
		
		$condition['show_type'] = '首页横幅';
		$condition['show_seq'] = substr($photo_id,4,1);
		$data['show_url'] = $url;	
		$Show->where($condition)->save($data);
		
		$this->redirect('showBanner');
	}
	
	public function uploadMember() {
		//防止页面乱码  
		header ( 'Content-type:text/html;charset=utf-8' );
		
		if(is_uploaded_file($_FILES['uploadPhoto']['tmp_name'])){
			$upfile=$_FILES["uploadPhoto"];
			$name=$upfile["name"]; //重命名照片
			$tmp=strtolower(substr($name, -4,4));
			$type=$upfile["type"];
			$size=$upfile["size"];
			$tmp_name=$upfile["tmp_name"];
			$error=$upfile["error"];
			
			if($_POST['sex']=='1') {
				for($i=1;$i<9;$i++) {
					if(!is_file('Public/Display/index/member/male0'.$i.'.jpg')) {
						$name=$i.$tmp;
						if($error=='0') move_uploaded_file($tmp_name,'Public/Display/index/member/male0'.$name);
						break;
					}			
				} 
			} else {
				for($i=1;$i<9;$i++) {
					if(!is_file('Public/Display/index/member/female0'.$i.'.jpg')) {
						$name=$i.$tmp;
						if($error=='0') move_uploaded_file($tmp_name,'Public/Display/index/member/female0'.$name);
						break;
					}			
				} 
			}
 		}
		$this->redirect('showMember');
	}
	
	public function uploadVip() {
		//防止页面乱码  
		header ( 'Content-type:text/html;charset=utf-8' );
		
		if(is_uploaded_file($_FILES['uploadPhoto']['tmp_name'])){
			$upfile=$_FILES["uploadPhoto"];
			$name=$upfile["name"]; //重命名照片
			$tmp=strtolower(substr($name, -4,4));
			$type=$upfile["type"];
			$size=$upfile["size"];
			$tmp_name=$upfile["tmp_name"];
			$error=$upfile["error"];
			
			if($_POST['sex']=='1') {
				for($i=1;$i<9;$i++) {
					if(!is_file('Public/Display/index/vip/male0'.$i.'.jpg')) {
						$name=$i.$tmp;
						if($error=='0') move_uploaded_file($tmp_name,'Public/Display/index/vip/male0'.$name);
						break;
					}			
				} 
			} else {
				for($i=1;$i<9;$i++) {
					if(!is_file('Public/Display/index/vip/female0'.$i.'.jpg')) {
						$name=$i.$tmp;
						if($error=='0') move_uploaded_file($tmp_name,'Public/Display/index/vip/female0'.$name);
						break;
					}			
				} 
			}
 		}
		$this->redirect('showVip');
	}
	
	public function uploadBanner() {
		//防止页面乱码  
		header ( 'Content-type:text/html;charset=utf-8' );
		
		if(is_uploaded_file($_FILES['uploadBanner']['tmp_name'])){
			$upfile=$_FILES["uploadBanner"];
			$name=$upfile["name"]; //重命名照片
			$tmp=strtolower(substr($name, -4,4));
			$type=$upfile["type"];
			$size=$upfile["size"];
			$tmp_name=$upfile["tmp_name"];
			$error=$upfile["error"];
			$name = $_POST['type'].$tmp; 
			if($error=='0') move_uploaded_file($tmp_name,'Public/Display/index/outing/'.$name);		
 		}
		$this->redirect('showBanner');
	}
	
	public function deleteMember() {
		//防止页面乱码  
		header ( 'Content-type:text/html;charset=utf-8' );
		$Show = M('Show');
		$photo_id = $_GET['photoid'];
		if(is_file('Public/Display/index/member/'.$photo_id.'.jpg')) 
			unlink('Public/Display/index/member/'.$photo_id.'.jpg');
		if(strlen($photo_id)==6) {
			$condition['show_type'] = '非缘莫属男';	
			$condition['show_seq'] = substr($photo_id,5,1);
			$data['show_url'] = '';	
			$Show->where($condition)->save($data);
		} else {
			$condition['show_type'] = '非缘莫属女';
			$condition['show_seq'] = substr($photo_id,7,1);
			$data['show_url'] = '';	
			$Show->where($condition)->save($data);
		}	
		$this->redirect('showMember');
	}
	
	public function deleteVip() {
		//防止页面乱码  
		header ( 'Content-type:text/html;charset=utf-8' );
		$Show = M('Show');
		$photo_id = $_GET['photoid'];
		if(is_file('Public/Display/index/vip/'.$photo_id.'.jpg')) 
			unlink('Public/Display/index/vip/'.$photo_id.'.jpg');
		if(strlen($photo_id)==6) {
			$condition['show_type'] = '绝对精英男';	
			$condition['show_seq'] = substr($photo_id,5,1);
			$data['show_url'] = '';	
			$Show->where($condition)->save($data);
		} else {
			$condition['show_type'] = '绝对精英女';
			$condition['show_seq'] = substr($photo_id,7,1);
			$data['show_url'] = '';	
			$Show->where($condition)->save($data);
		}	
		$this->redirect('showVip');
	}
	
	public function deleteBanner() {
		//防止页面乱码  
		header ( 'Content-type:text/html;charset=utf-8' );
		$Show = M('Show');
		$photo_id = $_GET['id'];
		if(is_file('Public/Display/index/outing/'.$photo_id.'.jpg')) 
			unlink('Public/Display/index/outing/'.$photo_id.'.jpg');
		if(strlen($photo_id)==5) {
			$condition['show_type'] = '首页横幅';	
			$condition['show_seq'] = substr($photo_id,4,1);
			$data['show_url'] = '';	
			$Show->where($condition)->save($data);
		}
		$this->redirect('showBanner');
	}
}